repeat
loops: one that repeats as long as a conditional test is not false (repeat
. . . while
), and one that repeats until the conditional test is not false (repeat
. . . until
). Each form has two variants, providing a total of four possible forms:repeat while conditional do expressionIn all four forms, conditional is the loop control expression, which must be an expression that evaluates to either
repeat untilconditional do expression
repeat expression while conditional
repeat expression untilconditional
false
or not false
, and expression is the body of the loop containing the expression (often a compound expression) that is executed at each iteration of the loop.
In the repeat
forms that have the expression before the conditional, the expression is evaluated at least once before the conditional is evaluated. In the other forms (the do
forms), if the while
test evaluates to false
, or the until
test to not false
, then expression is never evaluated.
All repeat
expressions return the OK
object, a special system object, regardless of the outcome of their conditional tests or actions.
global x := 10
repeat while x > 0 do (
print (sin x)
x := x - 1
)
x := 10
repeat (
print x
x := x - 1
) until x == 0
Using the exit
construct defined on page 92, you can exit from within a repeat loop, returning a different value.
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.